package com.linux.huhx.thread3.singleDesign_1;

import java.util.concurrent.TimeUnit;

/**
 * @Author: huhx
 * @Date: 2017-10-31 下午 4:59
 */
public class MyObject4 {
    private static MyObject4 myObject;

    private MyObject4() {}

    public static MyObject4 getInstance() {
        try {
            synchronized (MyObject4.class) {
                if (myObject == null) {
                    // 模拟一些准备的耗时操作
                    TimeUnit.SECONDS.sleep(2);
                    myObject = new MyObject4();
                }
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return myObject;
    }
}
